package com.android.scaclient;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONStringer;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.android.scaclient.json.JSONRpc;

public class SCAAndroidActivity extends Activity {
	/** Called when the activity is first created. */

	private static final String jsonRPCServiceURI = "http://157.159.42.29:8080/HelloJava";
	private static final String jsonRPCRequest = "{\"id\": 1, \"method\": \"helloJava\", \"params\": []}";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		TextView text = (TextView) findViewById(R.id.hellojava);

		JSONObject json = null;
		
		try {
			json = JSONRpc.invoke(jsonRPCServiceURI, jsonRPCRequest);

			if (json == null) {
				Log.d("User NULL", "jsoninvoke NULL");
				return;
			}

			String result = json.getString("result");
			text.setText(result);

		} catch (JSONException e) {
			e.printStackTrace();
			Log.d("User Exception", "jsoninvoke failed");

		}
	}
}